﻿Shader "gg/wave"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
        _Amount ("Amount", Range(0,1.0)) = 0.5
        _W ("W", Range(0,500)) = 20
        _Speed("Speed", Range(0,100)) = 10
    }
    SubShader
    {
        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                float4 vertex : SV_POSITION;
            };

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = v.uv;
                return o;
            }

            sampler2D _MainTex;
            float _Amount;
            float _W;
            float _Speed;

            fixed4 frag (v2f i) : SV_Target
            {
                float2 center_uv = {0.5, 0.5};
                float2 uv = i.uv;
                float2 dt = center_uv - uv;
                float len = sqrt(dot(dt, dt));
                float amount = _Amount / (_Amount + len * _Speed);
                if(amount < 0.05)
                {
                    amount = 0;
                }
                uv.y += amount * cos(len * _W);
                fixed4 col = tex2D(_MainTex, uv);
                return col;
            }
            ENDCG
        }
    }
}
